package Assignment;

import java.awt.*;
import javax.swing.*;

/**
 * Created by IntelliJ IDEA.
 * User: Sarah
 * Date: 17/08/2011
 * Time: 2:39:55 PM
 * To change this template use File | Settings | File Templates.
 */

public class elevatorUI extends JPanel {

    Timer gateTimer, cageTimer;
    boolean ifOpen;
    final int FREE = 0;
    int state, floor;
    int highestCall, lowestCall;
    int numOfFloor;
    int[] upStop, downStop, stop;
    int PanelWidth, PanelHeight, tagWidth, tagHeight, liftWidth, liftHeight, innerBtnWidth, innerBtnHeight;
    int stateHeight, stateWidth;

    elevator innerBtn;
    elevatorState liftState;
    elevatorShaft cage;
    floorNumbers tag;

    /**
     * Displays the elevators and floors according to the user's input
     */
    public elevatorUI(int numOfFloor) {

        setBackground(Color.lightGray);
        init(numOfFloor);
        innerBtn = new elevator(numOfFloor);
        liftState = new elevatorState();

        cage = new elevatorShaft(numOfFloor);
        tag = new floorNumbers(numOfFloor);

        setLayout(null);
        tag.setBounds(liftWidth + 9, 3, tagWidth, tagHeight);
        cage.setBounds(8, 3, liftWidth, liftHeight);

        innerBtn.setBounds(10 + tagWidth + liftWidth, 5, innerBtnWidth, innerBtnHeight);
        liftState.setBounds(10 + tagWidth + liftWidth, 30 + innerBtnHeight, stateWidth, stateHeight);
        add(tag);
        add(cage);
        add(innerBtn);
        add(liftState);
    }

    /**
     * Sets the boundaries for each level for the elevator
     */
    void init(int numOfFloor) {
        this.numOfFloor = numOfFloor;
        ifOpen = false;
        state = FREE;
        floor = 1;
        highestCall = numOfFloor + 1;
        lowestCall = 0;

        upStop = new int[numOfFloor + 1];
        downStop = new int[numOfFloor + 1];
        for (int i = 1; i <= numOfFloor; i++)
            upStop[i] = downStop[i] = 0;

        stop = new int[numOfFloor + 1];
        for (int i = 1; i <= numOfFloor; i++)
            stop[i] = 0;

        liftWidth = 70;
        liftHeight = 60 * numOfFloor;

        tagWidth = 30;
        tagHeight = liftHeight;

        innerBtnWidth = 150;
        innerBtnHeight = liftHeight / 3;

        stateWidth = 120;
        stateHeight = 2 * liftHeight / 9;

        PanelWidth = tagWidth + innerBtnWidth + liftWidth;
        PanelHeight = liftHeight+10;
	}
}
